#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>

#define N 10

int main()
{
    pid_t id =fork();
    if(id==0)
    {
        //子进程
        int cnt=3;
        while(cnt--)
        {
            printf("我是子进程:%d\n",getpid());
            sleep(1);
        }
        exit(1);
    }
    int status = 0;
    pid_t rid = waitpid(id,&status,0);
    if(rid>0)
    {
        printf("进程等待成功！\n");
        if(WIFEXITED(status))
        {
            printf("正常运行结束:%d\n",WEXITSTATUS(status));
        }

        else{
                 printf("进程异常了\n");
             }
        
    }
    return 0;
}
